package com.dv.web.controller.basic;

import com.dv.common.annotation.Log;
import com.dv.common.core.controller.BaseController;
import com.dv.common.core.domain.AjaxResult;
import com.dv.common.core.page.TableDataInfo;
import com.dv.common.enums.BusinessType;
import com.dv.common.utils.DateUtils;
import com.dv.driverless.domain.BasicParking;
import com.dv.driverless.domain.vo.BasicParkingVo;
import com.dv.driverless.service.IBasicParkingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 停车位信息表Controller
 *
 * @author ruoyi
 * @date 2023-04-01
 */
@RestController
@RequestMapping("/basic/parking")
public class BasicParkingController extends BaseController
{
    @Autowired
    private IBasicParkingService basicParkingService;

    /**
     * 查询停车位信息表列表
     */
    @PreAuthorize("@ss.hasPermi('basic:parking:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicParking basicParking)
    {
        startPage();
        List<BasicParkingVo> list = basicParkingService.selectBasicParkingList(basicParking);
        return getDataTable(list);
    }

    /**
     * 获取停车位信息表详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:parking:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(basicParkingService.selectBasicParkingById(id));
    }

    /**
     * 新增停车位信息表
     */
    @PreAuthorize("@ss.hasPermi('basic:parking:add')")
    @Log(title = "停车位信息表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicParking basicParking)
    {
        basicParking.setCreateDate(DateUtils.getNowDate());
        return toAjax(basicParkingService.insertBasicParking(basicParking));
    }

    /**
     *  修改停车位状态
     */
    @Log(title = "停车位信息", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeParkingStatus(@RequestBody BasicParking basicParking)
    {
        return toAjax(basicParkingService.changeBasicParking(basicParking));
    }

    /**
     * 修改停车位信息表
     */
    @PreAuthorize("@ss.hasPermi('basic:parking:edit')")
    @Log(title = "停车位信息表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicParking basicParking)
    {
        return toAjax(basicParkingService.updateBasicParking(basicParking));
    }

    /**
     * 删除停车位信息表
     */
    @PreAuthorize("@ss.hasPermi('basic:parking:remove')")
    @Log(title = "停车位信息表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(basicParkingService.deleteBasicParkingByIds(ids));
    }
}
